#!/bin/bash

# OAuth2.0登录功能测试脚本

echo "🚀 启动OAuth2.0登录功能测试..."
echo ""

# 检查必要的文件是否存在
echo "📁 检查文件结构..."

files=(
    "src/stores/user.js"
    "src/api/user.js"
    "src/utils/oauthHandler.js"
    "src/utils/loginHandler.js"
    "src/utils/oauthState.js"
    "src/components/LoginStatus.vue"
    "src/view/user/OAuthTest.vue"
    "src/App.vue"
    "src/router/index.js"
    "src/main.js"
)

missing_files=()
for file in "${files[@]}"; do
    if [ ! -f "$file" ]; then
        missing_files+=("$file")
    else
        echo "✅ $file"
    fi
done

if [ ${#missing_files[@]} -eq 0 ]; then
    echo ""
    echo "🎉 所有必要文件都存在！"
    echo ""
    echo "📋 OAuth2.0自动登录功能已实现："
    echo "   - 首页自动OAuth授权登录"
    echo "   - 特殊状态码处理 (50001, 50002, 50003)"
    echo "   - 全局登录状态管理"
    echo "   - 企业绑定自动跳转"
    echo "   - 测试页面 (/oauth-test)"
    echo ""
    echo "🌐 访问路由："
    echo "   - / - 首页（自动OAuth登录）"
    echo "   - /oauth-test - OAuth测试页面"
    echo "   - /company/bound - 企业绑定页面"
    echo ""
    echo "🔧 使用方法："
    echo "   1. npm run dev 启动开发服务器"
    echo "   2. 访问 http://localhost:5173/ 自动OAuth登录"
    echo "   3. 访问 http://localhost:5173/oauth-test 进行调试"
    echo ""
    echo "📖 详细文档请查看: OAUTH_LOGIN_README.md"
else
    echo ""
    echo "❌ 发现缺失文件："
    for file in "${missing_files[@]}"; do
        echo "   - $file"
    done
    echo ""
    echo "请检查文件是否正确创建！"
    exit 1
fi

echo ""
echo "✨ OAuth2.0登录功能部署完成！"